package com.jason.kotlinstudy

import android.graphics.Bitmap
import android.os.Bundle
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity

/**
 * 跨进程传递大图.
 */
class AnotherProcessActivity : AppCompatActivity() {

    private lateinit var bitmap: Bitmap
    private val TAG = AnotherProcessActivity::class.java.simpleName

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_aidl_bitmap)

        val bundle = intent.extras

        //返回IGetBitmapService类型
        val getBitmapService = IGetBitmapService.Stub.asInterface(bundle?.getBinder("mybinder"))
        val bitmap = getBitmapService.intentBitmap

//        val bitmapBinder = bundle!!.getBinder("bitmap") as BitmapBinder?
//        bitmap = bitmapBinder!!.bitmap
        bitmap?.let {
            Log.i(TAG, "Mani2Activity bitmap 大小" + bitmap.getByteCount() / 1024 + " kb")
            Log.i(TAG, "Mani2Activity bitmap 大小" + bitmap.getByteCount() / (1024 * 1024) + " mb")
            findViewById<ImageView>(R.id.iv_image).setImageBitmap(bitmap)
        }
    }
}